<template>
    <div>
        <h1>康复理疗添加</h1>
        <table border="1px" class="table table-bordered">
            <tbody>
                <tr>
                    <td>项目编号</td>
                    <td>
                        <input type="text" v-model="info.Number" disabled>
                    </td>
                </tr>
                <tr>
                    <td>项目名称</td>
                    <td>
                        <input type="text" v-model="info.KFName">
                    </td>
                </tr>
                <tr>
                    <td>佣金(元)</td>
                    <td>
                        <input type="text" v-model="info.Price">
                    </td>
                </tr>
                <tr>
                    <td>服务人数</td>
                    <td>
                        <input type="text" v-model="info.People">
                    </td>
                </tr>
                <tr>
                    <td>服务时长</td>
                    <td>
                        <input type="text" v-model="info.Ftime">
                    </td>
                </tr>
                <tr>
                    <td>项目说明</td>
                    <td>
                        <textarea v-model="info.Aera"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" :value="1" v-model="info.State"> 启用
                        <input type="radio" :value="0" v-model="info.State"> 禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button class="btn btn-primary" @click="ok">提交</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import moment from 'moment';
import { useRouter } from 'vue-router'
const router = useRouter();


let info: any = reactive({
  "Number": moment(new Date()).format('YYYYMMDD')+Math.random().toString().substring(2,5),
  "KFName": "",
  "Price": 0,
  "People":'',
  "Ftime": '',
  "Aera": "",
  "State": 1,
})


//添加
const ok = () => {
    if(info.KFName==""){
        alert('项目名称不能为空!');
        return;
    }
    if(info.Price==""){
        alert('佣金(元)不能为空!');
        return;
    }
    if(info.People==""){
        alert('服务人数不能为空!');
        return;
    }
    if(info.Ftime==""){
        alert('服务时长不能为空!');
        return;
    }
    if(info.Aera==""){
        alert('项目说明不能为空!');
        return;
    }
    let fwpeople = /^\+?[1-9][0-9]*$/;
    if(!fwpeople.test(info.People)){
        alert('服务人数必须是整数!');
        return;
    }
    if(!fwpeople.test(info.Ftime)){
        alert('服务时长必须是整数!');
        return;
    }
    axios({
        url: 'https://localhost:7118/api/KFliliao/AddKF',
        method: 'post',
        data: info
    })
        .then((res) => {
            if (res.data > 0) {
                alert('添加成功!');
                router.push('/kfshow')
            }
            else {
                alert('添加失败!');
            }
        })
}
</script>

<style scoped></style>